package com.cjb.cloudsecurity.userMsg.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjb.cloudsecurity.userMsg.entity.SysRole;
import com.cjb.cloudsecurity.userMsg.mapper.SysRoleMapper;
import com.cjb.cloudsecurity.userMsg.service.SysRoleService;
import com.cjb.common.mybatisUtil.impl.BaseRepositoryImpl;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;

/**
* @Author chenjinbin
* @Package IntelliJ IDEA
* @Class SysRolesServiceImpl
* @Date 2023-07-27 21:41
*/
@Service
@AllArgsConstructor
public class SysRoleRepositoryImpl extends BaseRepositoryImpl<SysRoleMapper, SysRole> implements SysRoleService {
/**
* 日志
*/
    private final static Logger log = LoggerFactory.getLogger(SysRoleRepositoryImpl.class);
    /*
    * 注入mapper层
    */
    private final SysRoleMapper sysRoleMapper;
    /**
    * 单体保存
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public boolean save(SysRole sysRole) {
        baseMapper.insert(sysRole);
        return true;
    }

    /**
    *批量保存
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public Integer listSave(List<SysRole> sysRole) {
        return sysRoleMapper.insertBatchSomeColumn(sysRole);
    }

    /**
    * 批量更新
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public void listUpdate(List<SysRole> sysRole) {
        sysRoleMapper.insertBatchSomeColumn(sysRole);
    }

    /**
    * 批量删除
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public void listDelete(List<SysRole> sysRole) {
        List<Long> collect = sysRole.stream().map(SysRole::getId)
        .distinct()
        .collect(Collectors.toList());
        sysRoleMapper.deleteBatchIds(collect);
    }
    /**
    * 通过id删除
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public int deleteById(SysRole sysRole) {
    return sysRoleMapper.deleteById(sysRole.getId());
    }

    /**
    *单个查询
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public SysRole queryById(SysRole sysRole) {
        return  sysRoleMapper.selectById(sysRole.getId());
    }

    @Override
    public Page queryPage(Page sysRolePage , SysRole sysRole) {
        return sysRoleMapper.selectMapsPage(sysRolePage, null);
    }

    /**
    * 返回全部信息
    *
    * @Author chenjinbin
    * @Value
    * @Title
    */
    @Override
    public List<SysRole> returnAllData() {
        return sysRoleMapper.selectList(null);
    }

}